package router

import (
	"github.com/gin-gonic/gin"
	"trpg-common/middleware"
)

func RegisterRouter(engine *gin.Engine) {
	engine.Use(middleware.Cors())     // 处理跨域
	engine.Use(middleware.Recovery()) // 全局异常处理
	noAuthGroup := engine.Group("")   // 不鉴权组
	group := engine.Group("")         // 鉴权组
	group.Use(middleware.Authorize)
	// base 基础接口
	baseGroup := group.Group("/base")
	// user 接口
	userGroup := baseGroup.Group("/user")
	noAuthGroup.POST("/base/user/logIn", userHandler.LogIn)
	noAuthGroup.POST("/base/user/register", userHandler.Register)
	userGroup.POST("/update", userHandler.UpdateInfo)
	userGroup.POST("/uploadAvatar", userHandler.UploadAvatar)
	userGroup.GET("/detail", userHandler.GetUserDetail)
	// character 接口
	characterGroup := group.Group("/character")
	characterGroup.POST("", characterHandler.InsertOrUpdateCharacter)
	characterGroup.POST("/upload/:id", characterHandler.UploadExcel)
	characterGroup.GET("/list", characterHandler.GetCharacterList)
	characterGroup.GET("/:id", characterHandler.GetCharacterDetail)
	// scripts接口
	scriptsGroup := group.Group("/scripts")
	scriptsGroup.POST("", scriptsHandler.AddOrUpdateScript)
	scriptsGroup.POST("/search", scriptsHandler.SearchScriptList)
	scriptsGroup.GET("/:id", scriptsHandler.GetScriptById)
	scriptsGroup.POST("/collect/:scriptId", scriptsHandler.CollectScripts)
	scriptsGroup.POST("/deleteCollection/:scriptId", scriptsHandler.DeleteScripts)
	// label接口
	labelGroup := group.Group("/label")
	labelGroup.POST("", labelHandler.AddLabel)
	labelGroup.GET("/list/:type", labelHandler.GetLabels)
	// room接口
	roomGroup := group.Group("/room")
	roomGroup.POST("", roomHandler.AddRoom)
	roomGroup.POST("/search", roomHandler.SearchRoomList)
	roomGroup.GET("/:id", roomHandler.GetRoomById)
	roomGroup.GET("/members/:id", roomHandler.GetMembers)
	roomGroup.POST("/members/delete/:uid/:username", roomHandler.DeleteMember)
	roomGroup.POST("/members/quit", roomHandler.QuitRoom)
	roomGroup.POST("/bindCharacter/:roomId/:characterId", roomHandler.BindCharacter)
	roomGroup.POST("/bindScript/:roomId/:scriptId", roomHandler.BindScript)
	roomGroup.POST("/apply", roomHandler.ApplyJoinRoom)
	roomGroup.POST("/dealWithApply/:uid/:flag", roomHandler.DealWithApply)
	roomGroup.POST("/messages/files", roomHandler.SendMessageFiles)
	roomGroup.GET("/messages/:roomId", roomHandler.GetRoomMessages)
	// 系统消息接口
	systemMessageGroup := group.Group("/systemMessage")
	systemMessageGroup.GET("/list", systemMessageHandler.GetSystemMessages)
	// 论坛接口
	forumGroup := group.Group("/forum")
	forumGroup.POST("/topic", forumHandler.NewTopic)
	forumGroup.POST("/topic/search", forumHandler.SearchTopicList)
	forumGroup.POST("/topic/like/:topicId", forumHandler.LikeTopic)
	forumGroup.POST("/topic/dislike/:topicId", forumHandler.DisLikeTopic)
	forumGroup.POST("/topic/collect/:topicId", forumHandler.CollectTopic)
	forumGroup.POST("/topic/cancelCollect/:topicId", forumHandler.CancelCollectTopic)
	forumGroup.POST("/topic/lock/:topicId", forumHandler.LockTopic)
	forumGroup.POST("/topic/unlock/:topicId", forumHandler.UnLockTopic)
	forumGroup.POST("/topic/delete/:topicId", forumHandler.DeleteTopic)
	forumGroup.POST("/content", forumHandler.NewContent)
	forumGroup.POST("/content/search", forumHandler.SearchContentList)
	forumGroup.POST("/content/like/:contentId", forumHandler.LikeContent)
	forumGroup.POST("/content/dislike/:contentId", forumHandler.DisLikeContent)
	forumGroup.POST("/reply", forumHandler.NewReply)
	forumGroup.GET("/reply/list", forumHandler.GetReplyList)
}
